import router from "@/router";

//路由权限相关

const allRoutes = [
  {
    id: "1",
    path: "",
    redirect: "/Admin/Home",
  },
  {
    id: "1",
    name: "Home",
    path: "Home",
    component: () => import("@/views/Admin/Home/index.vue"),
  },
  {
    id: "2",
    name: "Banner",
    path: "Banner",
    component: () => import("@/views/Admin/Banner/index.vue"),
  },
  {
    id: "3",
    name: "Operator",
    path: "Operator",
    component: () => import("@/views/Admin/Operator/index.vue"),
  },
  {
    id: "4",
    name: "Operatorone",
    path: "Operatorone",
    component: () => import("@/views/Admin/miaosha/Operatorone.vue"),
  },
  {
    id: "4-1",
    name: "recommend",
    path: "recommend",
    component: () => import("@/views/Admin/miaosha/recommend.vue"),
  },
  {
    id: "4-2",
    name: "search",
    path: "search",
    component: () => import("@/views/Admin/miaosha/search.vue"),
  },
  {
    id: "4-3",
    name: "productlist",
    path: "productlist",
    component: () => import("@/views/Admin/miaosha/productlist.vue"),
  },
  {
    id: "5",
    name: "Ditu",
    path: "Ditu",
    component: () => import("@/views/Admin/Ditu/index.vue"),
  },
  {
    id: "6",
    name: "Curve",
    path: "Curve",
    component: () => import("@/views/Admin/Curve/index.vue"),
  },
];
export const getCurrRouter = () => {
  //获取登陆时获取的用户相关的权限id信息
  const checkedkeys = JSON.parse(sessionStorage.getItem("checkedkeys") || "[]");
  let routes = allRoutes.forEach((item) => {
    //判断如果储存的id如果在路由子组件中存在
    if (checkedkeys.includes(item.id)) {
      //按钮处理权限
      let crud = ["0", "0", "0", "0"];

      if (checkedkeys.includes(item.id + "-C")) {
        crud[0] = "1"; //增
      }
      if (checkedkeys.includes(item.id + "-R")) {
        crud[1] = "1";
      }
      if (checkedkeys.includes(item.id + "-U")) {
        crud[2] = "1";
      }
      if (checkedkeys.includes(item.id + "-D")) {
        crud[3] = "1";
      }
      item.meta = { crud: crud.join("") };

      //那么就将添加一个新的路由纪录， 将其作为一个已有路由的子路由
      router.addRoute("Admin", item);
      //admin 已有路由   将item添加到admin下作为子路由
    }
  });
};
